package com.sxjh.controller.ny;

import com.sxjh.common.BaseController;
import com.sxjh.common.Result;
import com.sxjh.common.ResultException;
import com.sxjh.service.FileService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * <p>
 * 用户信息接口
 * </p>
 *
 * @author guanxy
 * @since 2023-06-03
 */
@Api(tags = "用户信息接口")
@RestController("/user")
@RequestMapping
public class UserController extends BaseController {

    @Autowired
    FileService fileService;

    @ApiOperation("用户信息接口")
    @GetMapping(value = "/query")
    public Result<Integer> query(HttpServletRequest request) {
        return Result.ok(getUserInfo(request));
    }

    @Deprecated
    @ApiOperation("上穿接口")
    @PostMapping(value = "/upload", consumes = "multipart/*", headers = "content-type=multipart/form-data")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "文件上传", required = true, dataTypeClass = MultipartFile.class)})
    public Result<Object> upload(@ApiParam(hidden = true) MultipartFile file) {
        try {
            CompletableFuture<String> ffff = fileService.savePhpFile(file);
            return Result.ok(ffff.get());
        } catch (ResultException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }


}
